package com.scaffold.myproject.web.controller;

import com.scaffold.myproject.common.Result;
import com.scaffold.myproject.common.BizException;
import com.scaffold.myproject.entity.demo.UserEntity;
import com.scaffold.myproject.model.req.demo.UserReq;
import com.scaffold.myproject.model.vo.demo.UserVO;
import com.scaffold.myproject.service.demo.UserService;
import com.scaffold.myproject.web.convert.UserConvert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * @author lx
 * @date 2025/6/5
 * @Description
 */
@Slf4j
@Api(tags = "用户管理")
@RestController("/user")
public class UserController {
    @Resource
    private UserService userService;
    @ApiOperation("用户列表")
    @GetMapping("/list")
    public List<UserVO> list()
    {
        throw new BizException("用户列表");
    }

    @ApiOperation("mybati-plus测试")
    @PostMapping("/add")
    public Result<String> add()
    {
        UserEntity userEntity = new UserEntity();
        userEntity.setEmployeeName("张三");
        userEntity.setGender(1);
        userEntity.setAge(18);
        userEntity.setPosition("程序员");
        userEntity.setEntryDate(LocalDate.now());
        userEntity.setAttributes("{\"name\":\"张三\"}");
        userService.save(userEntity);
        return Result.of();
    }

    @ApiOperation("mapstruct-plus测试")
    @PostMapping("/convert")
    public Result<UserVO> convert(@RequestBody UserReq userReq)
    {
        UserVO userVO = UserConvert.INSTANCE.DTOToVO(userReq);
        log.info("userVO: {}", userVO);
        return Result.of(userVO);
    }
}
